// axios.ts
import axios from 'axios';

import type {
    AxiosInstance,
    AxiosRequestConfig,
    InternalAxiosRequestConfig,
    AxiosResponse
  } from 'axios'

// 创建 Axios 实例
const axiosInstance: AxiosInstance = axios.create({
  baseURL: import.meta.env.VITE_API_BASE_URL as string, // 根据实际情况配置 baseURL
  timeout: 50000, // 设置超时时间
});


const axiosInstanceForAnalytics: AxiosInstance = axios.create({
  baseURL: 'https://www.clarity.ms/export-data/api',
  timeout: 5000,
})


// 请求拦截器
axiosInstance.interceptors.request.use(
  (config: InternalAxiosRequestConfig) => {
    // 在这里添加请求拦截逻辑，例如添加 token 等
    config.headers['Content-Type'] = "application/json" // 设置Content-Type
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

// 响应拦截器
axiosInstance.interceptors.response.use(
  (response: AxiosResponse) => {
    // 在这里添加响应拦截逻辑，例如处理错误信息等
    return response;
  },
  (error) => {
    return Promise.reject(error);
  }
);


axiosInstanceForAnalytics.interceptors.request.use(
  (config: InternalAxiosRequestConfig) => {
    // 在这里添加请求拦截逻辑，例如添加 token 等
    config.headers['Content-Type'] = "application/json" // 设置Content-Type
    config.headers['Authorization'] = "Bearer " + 'eyJhbGciOiJSUzI1NiIsImtpZCI6IjQ4M0FCMDhFNUYwRDMxNjdEOTRFMTQ3M0FEQTk2RTcyRDkwRUYwRkYiLCJ0eXAiOiJKV1QifQ.eyJqdGkiOiI1NjUwYjAyYi02N2FjLTRjNzctOTk2Ni1hYzM2YTk3OTI3M2MiLCJzdWIiOiIyMzEyMjM5MzI4Mzg5ODU0Iiwic2NvcGUiOiJEYXRhLkV4cG9ydCIsIm5iZiI6MTcxODM0NzAxMiwiZXhwIjo0ODcxOTQ3MDEyLCJpYXQiOjE3MTgzNDcwMTIsImlzcyI6ImNsYXJpdHkiLCJhdWQiOiJjbGFyaXR5LmRhdGEtZXhwb3J0ZXIifQ.CXJC1YquUIFYqerx1ePd6e0jXHsHsAolxUXT5Ele8cHDLdDWu1-Y2aOnHXLixIJ7z1ES187CPmuWnm5kE4QM5nDfOTqR1Rq3_2kwkOJ8dYsnb2DCE0zYufHGFy-ENFC9bG5b8tWwEEIv8Bx4FiWqq0w-q0ZW4tykI16xHbKyQH76nUNVZ7oyP-7-LQaUqTYHgYkJnEwwrhisJ8E7obD-UwEwyoVxdD3EcgtZxSU3uEN6nCsFRuvU8sG1iPUde843oNcoN0Pqy-zX2BXAVjsmfkQPb8S-YpynZxjDxc7q7OL0ScO0YKTF1b97qVyUgDZY98CRCPYgSqk97efod4z6tg'
    config.headers['Access-Control-Allow-Origin'] = "*"
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

axiosInstanceForAnalytics.interceptors.response.use(
  (response: AxiosResponse) => {
    // 在这里添加响应拦截逻辑，例如处理错误信息等
    return response;
  },
  (error) => {
    return Promise.reject(error);
  }
);



export {
  axiosInstance,
  axiosInstanceForAnalytics
} ;